from django.db import models
from mlh.utils.models import BaseModel
from users.models import User


# 吐槽首页模型类

class Tsukkomi_Details(BaseModel):
    user_id = models.ForeignKey(User, verbose_name='用户id', on_delete=models.CASCADE)
    username = models.CharField(verbose_name='用户名', max_length=32)
    signature = models.IntegerField(verbose_name='点赞', default=0)
    datetime = models.DateField(verbose_name='时间')
    publishs = models.TextField(verbose_name='吐槽概要')


    def __str__(self):
        return self.username

    class Meta:
        db_table = 'Tsukkomi_Details'
        verbose_name = '吐槽首页'
        verbose_name_plural = verbose_name


# 吐槽评论表
class Comments(BaseModel):
    username = models.CharField(max_length=46, verbose_name='用户名')
    user_id = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户id')
    Tsukkomi_id = models.ForeignKey(Tsukkomi_Details, on_delete=models.PROTECT, verbose_name='吐槽列表id')
    content = models.TextField(verbose_name='吐槽内容')
    parent_id = models.ForeignKey('self', on_delete=models.PROTECT, verbose_name='父评论id', null=True, blank=True)
    like_content = models.IntegerField(verbose_name='点赞数', default=0)


    class Meta:
        db_table = 'Comments'
        verbose_name = '用户评论表'
        verbose_name_plural = verbose_name






# 吐槽点赞表
class SpitLike(BaseModel):
    spit_id = models.ForeignKey(Tsukkomi_Details, verbose_name='评论id', on_delete=models.PROTECT)
    user_id = models.ForeignKey(User, verbose_name='用户id', on_delete=models.PROTECT)

    class Meta:
        db_table = 'Comment_Like'
        verbose_name = '吐槽点赞'
        verbose_name_plural = verbose_name

class CommentLike(models.Model):
    """评论点赞"""
    comment_id = models.ForeignKey(Tsukkomi_Details, on_delete=models.CASCADE, verbose_name="评论id")
    user_id = models.ForeignKey(User, related_name='user_spit_comment_like', on_delete=models.CASCADE,
                                verbose_name="所属用户")

    class Meta:
        db_table = 'Tsukkom_comment_like'
        verbose_name = '评论点赞'
        verbose_name_plural = verbose_name

# 收藏表
class Collect(BaseModel):
    user_id = models.ForeignKey(User, verbose_name='用户id')
    Tsukkomi_id = models.ForeignKey(Tsukkomi_Details, verbose_name='吐槽id')

    class Meta:
        db_table = 'Collect'
        verbose_name = '收藏表'
        verbose_name_plural = verbose_name
